/*
 * Copyright 2011 Michael Nitsche
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package de.mnit.basis.swt.spezial.suche;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;

import de.mnit.basis.daten.konstant.position.POSITION_V;
import de.mnit.basis.swt.anw.A_MN_Gruppe;
import de.mnit.basis.swt.element.S_SWT_Komponente;
import de.mnit.basis.swt.element.steuer.rollbar.SWT_TextEingabe;
import de.mnit.basis.swt.layout.LayoutGitter;
import de.mnit.basis.sys.event.S_Zuhoerer;


/**
 * @author Michael Nitsche
 * 11.01.2011	Erstellt
 */
public class K_SucheFlach2 extends A_MN_Gruppe<K_SucheFlach2> implements S_KSuche {

	public static void main(String[] args)   { start(K_SucheFlach2.class,600,400); }


	private static final String E_SUCHE="suche";
	public SWT_TextEingabe	k_suche	= new SWT_TextEingabe().s1_Style(SWT.SEARCH | SWT.CANCEL);


	public void eSuche(S_Zuhoerer<String> z) {
		t.zuhoererPlus(E_SUCHE, z);
	}

	public void sLeer() {
		if(this.gText().length()==0)
			return;
		this.k_suche.sText("");
	}

	public String gText() {
		return this.k_suche.gText();
	}

	public void sSichtbar(boolean b) {
		t.k_suche.sSichtbar(b);
	}

	public void sAktiviert(boolean b) {
		t.k_suche.sAktiviert(b);
	}

	public void sFokus() {
		t.k_suche.sFokus();
	}


	protected S_SWT_Komponente<?, ? extends Composite> layout() {
		return LayoutGitter.neu()
			.sSpaltenAnzahl(2)
			.sKomponente(t.k_suche)
				.sFlexibelH()
//				.sHoehe(18)
				.sPositionV(POSITION_V.MITTE)
			.fertig();
	}

	protected void initStyle() {}

	protected void initEvents() {
		t.k_suche.eAenderung(new Listener(){
			public void handleEvent(Event arg0) {
				t.zuhoererStart(E_SUCHE, t.k_suche.gText());
			}
		});
	}

}
